package com.geekhole.demo.app.order;

import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import static com.geekhole.demo.app.TimeUtil.sleep;

@Service
public class OrderApplication {

    public List<Order> getByUser(Long userId){
        sleep(50);
        List<Order> orders = new ArrayList<>();
        for (int i = 0; i< 10; i++){
            Order order = new Order();
            orders.add(order);
            order.setId(createId());
            order.setUserId(createId());
            List<OrderItem> items = new ArrayList<>();
            order.setItems(items);
            for (int j = 0; j < 5; j++){
                OrderItem orderItem = new OrderItem();
                items.add(orderItem);
                orderItem.setId(createId());
                orderItem.setOrderId(order.getId());
                orderItem.setShopId(createId());
                orderItem.setProductId(createId());
            }
        }
        return orders;
    }

    private Long createId(){
        Random random = new Random();
        return Math.abs(random.nextLong());
    }
}
